package com.matrix.draft.helloworld.juc;

public class TestJoin {
    public static void main(String[] args) throws Exception {

        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                try {
                    Thread.sleep(1 * 1000);
                    System.out.println(Thread.currentThread().getName()+": "+i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 15; i++) {
                try {
                    Thread.sleep(1 * 1000);
                    System.out.println(Thread.currentThread().getName()+": "+i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread t3 = new Thread(() -> {
            for (int i = 0; i < 8; i++) {
                try {
                    Thread.sleep(1 * 1000);
                    System.out.println(Thread.currentThread().getName()+": "+i);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        t2.start();
        t3.start();
        t1.join();
        t2.join();
        t3.join();
        System.err.println("Thread main finished");
    }
}
